Skip to content

fix(tracing): release owned recorders on instance teardown - #504

Draft
SaKaNa-Y wants to merge 1 commit into
devframes:mainfrom
SaKaNa-Y:fix/owned-tracing-teardown
Draft

SaKaNa-Y wants to merge 1 commit into
devframes:mainfrom
SaKaNa-Y:fix/owned-tracing-teardown

Conversation

@SaKaNa-Y

@SaKaNa-Y SaKaNa-Y commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Closing a devframe or hub while its local recorder was active left that recorder subscribed to Node's diagnostics channel. If a replacement recorded the same channel in the same process, both instances captured the next call. Setup could leave the same subscription behind if it started recording and then threw.

initDevframe() and initHub() now register tracing cleanup when they create a context, before setup runs.

On close or setup failure
  Instance's own context    Stop local recording and close its trace streams.
                            Detach listeners from external recorders.
  Caller-supplied context   Leave tracing with the caller.

Evidence

Before: The reproduction closed one instance, started its replacement, and traced a call that returned 123. Both recorders captured that call. Stopping the replacement still left a subscriber on the channel.

After: In the same reproduction, only the replacement captured 123. For both entry points, the setup-failure tests also confirmed that the original error reached the caller and the local subscription was gone.

Merge Danger

Door: Two-way. Reverting restores the previous cleanup behavior.

Blast Radius: Tracing. Stopping an external recorder would make its owner miss later calls. The close tests confirm that an attached tool and a caller with a shared hub context can each record another call.

Register tracing cleanup when an instance acquires its context so close and setup failure both release local recording and relay subscriptions. Keep independently owned recorders and caller-supplied Hub contexts active.
@vercel

vercel Bot commented Nov 21, 2026

Copy link
Copy Markdown

@SaKaNa-Y is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown

👁️‍🗨️ Review this pull request with grouped, summarized diffs at:
👉 https://pulls.review/gh/devframes/devframe/504?from=github-actions[bot]

raw result

💭 analyzed by vercel-ai-gateway/anthropic/claude-sonnet-5
🕰️ 2026-11-21 08:25 UTC
🔗 head 8609c9c
🤖 automated by pulls.review

{
  "headSha": "8609c9c62bb4d07925350e135c87cf7179961fab",
  "result": {
    "overallSummary": "Fixes a tracing leak: closing (or failing to initialize) a devframe/hub instance left its local tracing subscription active on Node's diagnostics channel, so a replacement instance in the same process could keep recording events for the closed one. The fix tracks ownership of the tracing host per instance and disposes it (subscriptions, stream, timer, listeners) on close/init-failure, while preserving recorders owned by attached tools or caller-supplied Hub contexts.",
    "groups": [
      {
        "key": "tracing-lifecycle-fix",
        "label": "Tracing lifecycle fix",
        "summary": "Tracks which tracing sources a devframe/hub instance owns and releases them (local subscription, stream, timer, listeners) on close or failed setup, while leaving caller-supplied Hub contexts and attached tools' own recorders untouched. `attach()`/`detach()` now tolerate reattachment and failing unsubscribe calls during teardown.",
        "category": "core",
        "filePaths": [
          "packages/devframe/src/node/host-tracing.ts",
          "packages/devframe/src/node/instance-shell.ts",
          "packages/devframe/src/adapters/initiate.ts",
          "packages/hub/src/node/initiate.ts"
        ],
        "critical": true,
        "fileNotes": [
          {
            "path": "packages/devframe/src/node/host-tracing.ts",
            "text": "Core of the fix: `dispose()` stops local recording and unsubscribes all attached sources without stopping their recorders; `attach`/`detach` are hardened against reentrancy and throwing unsubscribers."
          },
          {
            "path": "packages/devframe/src/node/instance-shell.ts",
            "text": "New `ownTracing()` hook lets `initDevframe`/`initHub` register the tracing host they created so it's disposed on `close()` or if `init()` rejects."
          }
        ]
      },
      {
        "key": "tracing-tests",
        "label": "Tracing lifecycle tests",
        "summary": "Regression coverage for the new teardown behavior: reattachment during unsubscribe, instance close while a tool keeps its own recorder, failed setup, and caller-owned Hub contexts surviving close/failed setup.",
        "category": "tests",
        "filePaths": [
          "packages/devframe/src/node/__tests__/host-tracing.test.ts",
          "packages/hub/src/node/__tests__/tracing-lifecycle.test.ts"
        ],
        "fileNotes": [
          {
            "path": "packages/hub/src/node/__tests__/tracing-lifecycle.test.ts",
            "text": "New end-to-end test file exercising both `initDevframe` and `initHub` entry points plus the borrowed-context case."
          }
        ]
      },
      {
        "key": "api-snapshot",
        "label": "API snapshot update",
        "summary": "Generated type snapshot updated to reflect the new `ownTracing` method on `InstanceShellApi`.",
        "category": "other",
        "filePaths": [
          "tests/__snapshots__/tsnapi/devframe/internal.snapshot.d.ts"
        ],
        "fileNotes": [
          {
            "path": "tests/__snapshots__/tsnapi/devframe/internal.snapshot.d.ts",
            "text": "Auto-generated from the public type surface; no manual review needed beyond confirming it matches `instance-shell.ts`."
          }
        ]
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-11-21T08:25:59.775Z",
    "model": "vercel-ai-gateway/anthropic/claude-sonnet-5",
    "locale": "en"
  }
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant